<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>减刑假释信息添加</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:100px;
        }
        .input {
            width:100px;
        }
    </style>
</head>
<body>
<div class="mini-fit" id="en" style="padding-top:20px;margin-bottom:45px;">
    <form id="form1" method="post">
        <input name="priNum" id="priNum" class="mini-hidden" value="${priNum!''}" />
        <table align="center" cellspacing="8">
            <tr>
                <td class="discell">原刑期起日:</td>
                <td class="input">
                    <input name="pribegin" id="pribegin" class="mini-textbox" style="width:220px"
                           value="${pribegin!''}" readonly />
                </td>
            </tr>
            <tr>
                <td class="discell">原刑期止日:</td>
                <td class="input">
                    <input name="pristopold" id="pristopold" class="mini-textbox" style="width:220px"
                           value="${pristopold!''}" readonly />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>现刑期类型:</td>
                <td class="input">
                    <input name="subRange" id="subRange" class="mini-combobox" required="true" style="width:220px"
                           textField="codeName" valueField="codeId" emptyText="请选择现刑期类型..." onvaluechanged="changeSubRange()"
                           url="/azbj/inmates/baseinfo/getTbsysCode?codeType=2_14&pcodeId=-1&sn=0" showNullItem='true'
                           value="${subRange!''}"
                    />
                </td>
            </tr>
            <tr>
                <td class="discell">现刑期止日:</td>
                <td class="input">
                    <input property="editor" class="mini-datepicker" id="priStop" name="priStop" allowInput="false" format="yyyy-MM-dd"
                           style="width:220px" emptyText="请选择刑期止日" />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="red">注:</font></td>
                <td class="discell">
                    <font color="red">死缓减为无期不需要输入刑期止日</font>
                </td>
            </tr>
        </table>
    </form>
</div>
<div style="width:100%;position:absolute;bottom:0;line-height: 45px;border-top: 1px solid #dfdfdf;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" style="font-size: 15px" onclick="saveData()">保存</a>
    <a class="mini-button" iconCls="fa-close" plain="true" style="font-size: 15px" onclick="onCancel()">关闭</a>
</div>
<script type="text/javascript">

    mini.parse();
    setInputEnabled(['pribegin', 'pristopold']);
    var form = new mini.Form("form1");

    // 保存减刑假释信息数据
    function saveData() {
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        var priStopTemp = data.priStop;
        var pristopold = data.pristopold;
        var subRange = data.subRange;
        if (subRange == '9999') {//有期徒刑判断刑期止日是否填写
            if (priStopTemp == '' || priStopTemp == null) {
                mini.alert("有期徒刑必须填写现刑期止日");
                return;
            }
            if (priStopTemp < pristopold) {
                mini.alert("现刑期止日小于原刑期止日，请核对后填写");
                return;
            }
        }

        if (priStopTemp != "") {
            data.priStop = priStopTemp.format("yyyy-MM-dd");
        }
        var json = mini.encode(data);
        $.ajax({
            url: "/azbj/yazgl/xxbl/jxjs/save",
            data: {data: json},
            type: "post",
            success: function (success) {
                if (success.code == 1) {
                    mini.alert("保存成功", "信息提示", function () {
                        onCancel();
                    });
                } else if (success.code == 5599) {
                    mini.alert(success.message);
                } else {
                    mini.alert(success.message)
                }
            }
        });
    }

    Date.prototype.format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1,                 //月份
            "d+": this.getDate(),                    //日
            "h+": this.getHours(),                   //小时
            "m+": this.getMinutes(),                 //分
            "s+": this.getSeconds(),                 //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        return fmt;
    }

    function changeSubRange() {
        var subRangeValue = mini.get("subRange").getValue();
        if (subRangeValue == "9997" || subRangeValue == "9996" || subRangeValue == "9995") {//无期死缓不可输入刑期止日
            mini.get("priStop").setValue(null);
            mini.get("priStop").disable();
        } else {
            mini.get("priStop").enable();
        }
    }
</script>
</body>
</html>